<template>
    <div class="steps-wrap">
        <div class="progress">流程进度({{ props.current?.split('-')[0] }}/{{ total }})</div>
        <div class="steps">
            <div class="step-item" v-for="(item, index) in columns" :key="item.title">
                <div class="line" v-if="index != 0"></div>
                <div class="dot" :class="[item.active ? 'active-dot' : '', item.isLast ? 'last-active' : '', 'error']">
                    <span class="dot-inner" :class="[item.active ? 'active-dot-inner' : '']"></span>
                    <div :class="['title', item.active ? 'active' : '']">{{ item.title }}</div>
                    <div class="child" v-if="item.child">
                        <div class="child-steps">
                            <div class="child-items" v-for="el in item.child" :key="el.title">
                                <div class="child-item-left">
                                    <div class="child-line"></div>
                                    <div class="dot"
                                        :class="[el.active ? 'active-dot' : '', , el.isLast ? 'last-active' : '', 'error']">
                                        <span class="dot-inner" :class="[el.active ? 'active-dot-inner' : '']"></span>
                                    </div>
                                </div>
                                <div :class="['child-title', el.active ? 'active' : '']"> {{ el.title }}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
interface StepItem {
    title: string
    description: string
    child?: StepItem[]
    active?: boolean
    isLast?: boolean
}
import { ref } from 'vue';

const props = defineProps(['current']);
const columns = ref<StepItem[]>([
    {
        title: '投递简历',
        description: "",
    },
    {
        title: '简历筛选',
        description: "",
    },
    {
        title: '面试环节',
        description: "",
        child: [
            {
                title: '约面',
                description: "",
            },
            {
                title: '面试',
                description: "",
            }
        ]
    },
    {
        title: '培训环节',
        description: "",
        child: [
            {
                title: '约培',
                description: "",
            },
            {
                title: '到培',
                description: "",
            },
            {
                title: '培训中',
                description: "",
            },
            {
                title: '考核',
                description: "",
            }
        ]
    },
    {
        title: '发放Offer',
        description: "",
    },
    {
        title: '签约',
        description: "",
    },
])
const active = ref<string>("0")
watch(() => props.current, (val) => {
    const str = String(val);
    active.value = str
}, { immediate: true })
columns.value.forEach((item, idx) => {
    let index = +active.value.split("-")[0]
    let subIndex = +active.value.split("-")[1]
    if (index === idx + 1) {
        item.isLast = true
    }
    if (idx < index) {
        item.active = true
        if (item.child) {
            item.child.forEach((el, i) => {
                el.active = true
                if (index == idx + 1) {
                    el.isLast = true
                    if (i + 1 > subIndex) {
                        el.active = false
                        el.isLast = false
                    }
                }
            })
        }
    }

})

const now = ref<number>(0)
const total = ref<number>(6)
</script>
<style lang="scss" scoped>
.active {
    color: #333 !important;
}

.active-dot {
    background: rgba(32, 158, 228, 0.2) !important;
}

.active-dot-inner {
    background: #209EE4 !important;
}

.last-active {
    width: 16px;
    height: 16px;
    background: #209EE4 !important;
    border-radius: 50%;
    position: relative;
    color: #fff;

    &::after {
        content: "...";
        position: absolute;
        top: -50%;
    }
}

// .error {
//     background: #ff4242 !important;
//     color: #fff;

//     .active-dot-inner {
//         background: #ff4242 !important;
//     }

//     &::after {
//         content: "x";
//         position: absolute;
//         top: -40%;
//     }
// }

.progress {
    color: #333;
    font-size: 20px;
    font-weight: 500;
    margin: 24px 0 60px 0;
}


.steps {
    display: flex;
    margin-left: 20px;

    .step-item {
        display: flex;
        justify-content: center;
        align-items: center;

        .title {
            text-align: center;
            position: absolute;
            top: -30px;
            width: 120px;
            left: 50%;
            transform: translateX(-50%);
            font-weight: 500;
            font-size: 16px;
            color: #B1BABF;
            line-height: 19px;
        }

        .dot {
            width: 16px;
            height: 16px;
            background: #F3F8FA;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 0 5px;
            position: relative;

            .dot-inner {
                width: 9px;
                height: 9px;
                background: #C8DBE5;
                border-radius: 50%;
            }
        }
    }

    .line {
        width: 130px;
        height: 0px;
        margin: 0 5px;
        border-bottom: 1px dashed #ACCCDE;
    }
}

.child-steps {
    position: absolute;
    width: 100px;
    left: -5px;
    top: 20px;
}

.child-items {
    display: flex;
    align-items: center;

    .child-line {
        height: 42px;
        width: 0;
        border-right: 1px dashed #ACCCDE;
        margin: 10px 0;
    }

    .child-item-left {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .child-title {
        margin-top: 60px;
        margin-left: 5px;
        font-size: 16px;
        color: #B1BABF;
        line-height: 19px;
    }
}
</style>